//app.js
const util = require("utils/util.js");
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)


    if (this.globalData.openId) {
      // console.log("老用户")
      // console.log(app.globalData.openId)
    } else {
      // 登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId
          // console.log(res.code)
          // 获取openId
          let openidUrl = this.globalData.baseUrl + "getOpenId"
          let data = {
            js_code: res.code
          }
          util.requestLoading(openidUrl, data, "GET").then(res => {
            this.globalData.openId= res.data.openid
            openidUrl = this.globalData.baseUrl + "getCidByOpenid"
            data = {
              js_openid: res.data.openid
            }
            util.requestLoading(openidUrl, data, "GET").then(res => {
              this.globalData.cid= res.data.cid
              wx.setStorageSync('cid', res.data.cid)
            })
          })
        }
      })
    }
    
  },
  globalData: {
    userInfo: null,
    addressId:null,
    // baseUrl: "http://192.168.0.102/weixin/",
    baseUrl: "https://www.cnssoar.cn/twtf/weixin/",
    birthday:0,
    aid:0,//转发者id
    cid:0,//本人id
  }
})